package org.shareworth.online_life.util;

import com.google.gwt.user.client.ResponseTextHandler;

public class Struts2GWTHelper {

	 

    /**

     * Make asynchronous post

     * @param url Action url

     * @param formId id of form that will be posted

     * @param handler callback function

     */

    public static native void asyncPost(String url, String formId, ResponseTextHandler handler) /*-{

        dojo = $wnd.dojo;

        //don't use the dojo.io.bind({...}) shortcut, it doesn't work here

        var request = new dojo.io.Request(url);

        request.load = function(type, data, request) {

            handler.@com.google.gwt.user.client.ResponseTextHandler::onCompletion(Ljava/lang/String;)(data);

        };

        request.formNode = dojo.byId(formId);

        request.method = "POST";

        $wnd.dojo.io.bind(request);

    }-*/;

 

    /**

     * Make asynchronous post

     * @param url Action url

     * @param handler callback function

     */

    public static void asyncPost(String url, ResponseTextHandler handler) {

        Struts2GWTHelper.asyncPost(url, handler);

    }

}